<?php
header("Content-Type: application/json; charset=UTF-8");
require_once 'db.php';

$id = isset($_GET['id']) ? intval($_GET['id']) : 0;

if ($id <= 0) {
    echo json_encode([
        'status' => 'error',
        'message' => '无效的教练ID'
    ]);
    exit;
}

$sql = "SELECT c.*, cc.name as category_name 
        FROM coaches c 
        LEFT JOIN coach_categories cc ON c.category_id = cc.id 
        WHERE c.id = ? AND c.status = 1";

$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $id);
$stmt->execute();
$result = $stmt->get_result();

if ($result->num_rows > 0) {
    $coach = $result->fetch_assoc();
    echo json_encode([
        'status' => 'success',
        'coach' => $coach
    ]);
} else {
    echo json_encode([
        'status' => 'error',
        'message' => '教练不存在'
    ]);
}

$stmt->close();
$conn->close();
?> 